package com.kfm.dao;

import com.kfm.model.User;
import com.kfm.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 处理 User 表的 CURD
 */
public class UserDao {

    /**
     * 按照用户名和密码查询用户信息
     * @param username 输入的用户名
     * @param password 输入的密码
     * @return 查询到的用户信息
     */
    public User selectByUsernameAndPassword(String username, String password) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "select * from users where name = ? and password = ?";
        return queryRunner.query(DataSourceUtils.getConnection(), sql,  new BeanHandler<>(User.class), username, password);
    }
}
